﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace StaffingSystem.Filters
{
    [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)]
    public class LoginFilter : ActionFilterAttribute
    {
        /// <summary>  
        /// OnActionExecuting是Action执行前的操作  
        /// </summary>  
        /// <param name="filterContext"></param>  
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //ActionExecutingContext动作执行上下文
            //判断Cookie用户名密码是否存在  
            //HttpCookie cookieName = System.Web.HttpContext.Current.Request.Cookies.Get("name");
            //判断Session用户名密码是否存在  
            if (filterContext.HttpContext.Session["name"] == null)
            {
                filterContext.Result = new RedirectResult("/Login/Login");//第一个为控制器名 第二个为方法名（动作名）
            }
        }
    }
}